struct TreeNode* dfs(struct TreeNode* root,struct TreeNode* p, struct TreeNode* q)
{
    if(root==NULL||root==p||root==q) //返回当前节点的值
    {
        return root;
    }
    struct TreeNode* left = dfs(root->left,p,q);
    struct TreeNode* right = dfs(root->right,p,q);
    if(left==NULL&&right==NULL)
    {
        return NULL;
    }
    else if(left==NULL)
    {
        return right;
    }
    else if(right==NULL)
    {
        return left;
    }
    else{
        return root;
    }
}

struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) {
    return dfs(root,p,q);
}
